package com.taxiApp.controller;


import com.taxiApp.domain.PassengerDriverLink;
import com.taxiApp.server.PassengerDriverService;
import com.taxiApp.util.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/link")
public class PassengerDriverController {

    @Autowired
    PassengerDriverService passengerDriverService;

    @RequestMapping(value = "/add")
    @ResponseBody
    public BaseResponse add(@RequestBody PassengerDriverLink link) {


        try {

            if(link!=null &&link.getDriverName()!=null&&link.getPassengerName()!=null){
                passengerDriverService.saveLink(link);
                return BaseResponse.SUCCESS;
            }else {
                throw new Exception("乘客和司机信息不能为空！");
            }

        } catch (Exception ex) {
            return new BaseResponse(500, false, ex.getMessage(), null);
        }

    }


    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse delete(@RequestBody PassengerDriverLink link) {

        try {
            passengerDriverService.deleteLink(link);
            return BaseResponse.SUCCESS;
        } catch (Exception ex) {
            return new BaseResponse(500, false, ex.getMessage(), null);
        }

    }

}
